package vip.liux.contracts.infrastructure.pay.impl.mock;


import vip.liux.contracts.infrastructure.pay.dto.order.ClientPayOrderDto;
import vip.liux.contracts.infrastructure.pay.dto.order.PayOrderUnifiedDto;
import vip.liux.contracts.infrastructure.pay.dto.refund.ClientPayRefundDto;
import vip.liux.contracts.infrastructure.pay.dto.refund.PayRefundUnifiedDto;
import vip.liux.contracts.infrastructure.pay.dto.transfer.ClientPayTransferDto;
import vip.liux.contracts.infrastructure.pay.dto.transfer.PayTransferUnifiedDto;
import vip.liux.contracts.infrastructure.pay.impl.AbstractPayClient;
import vip.liux.contracts.infrastructure.pay.impl.NonePayClientConfig;
import vip.liux.contracts.shared.enums.pay.PayChannelCode;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 模拟支付的 PayClient 实现类
 * <p>
 * 模拟支付返回结果都是成功，方便大家日常流畅
 *
 * @author jason
 */
public class MockPayClient extends AbstractPayClient<NonePayClientConfig> {

    private static final String MOCK_RESP_SUCCESS_DATA = "MOCK_SUCCESS";

    public MockPayClient(Long channelId, NonePayClientConfig config) {
        super(channelId, PayChannelCode.MOCK.getCode(), config);
    }

    @Override
    protected void doInit() {
    }

    @Override
    protected ClientPayOrderDto doUnifiedOrder(PayOrderUnifiedDto reqDto) {
        return ClientPayOrderDto.successOf("MOCK-P-" + reqDto.getOutTradeNo(), "", LocalDateTime.now(),
                reqDto.getOutTradeNo(), MOCK_RESP_SUCCESS_DATA);
    }

    @Override
    protected ClientPayOrderDto doGetOrder(String outTradeNo) {
        return ClientPayOrderDto.successOf("MOCK-P-" + outTradeNo, "", LocalDateTime.now(),
                outTradeNo, MOCK_RESP_SUCCESS_DATA);
    }

    @Override
    protected ClientPayRefundDto doUnifiedRefund(PayRefundUnifiedDto reqDto) {
        return ClientPayRefundDto.successOf("MOCK-R-" + reqDto.getOutRefundNo(), LocalDateTime.now(),
                reqDto.getOutRefundNo(), MOCK_RESP_SUCCESS_DATA);
    }

    @Override
    protected ClientPayRefundDto doGetRefund(String outTradeNo, String outRefundNo) {
        return ClientPayRefundDto.successOf("MOCK-R-" + outRefundNo, LocalDateTime.now(),
                outRefundNo, MOCK_RESP_SUCCESS_DATA);
    }

    @Override
    protected ClientPayTransferDto doParseTransferNotify(Map<String, String> params, String body, Map<String, String> headers) {
        throw new UnsupportedOperationException("未实现");
    }

    @Override
    protected ClientPayRefundDto doParseRefundNotify(Map<String, String> params, String body, Map<String, String> headers) {
        throw new UnsupportedOperationException("模拟支付无退款回调");
    }

    @Override
    protected ClientPayOrderDto doParseOrderNotify(Map<String, String> params, String body, Map<String, String> headers) {
        throw new UnsupportedOperationException("模拟支付无支付回调");
    }

    @Override
    protected ClientPayTransferDto doUnifiedTransfer(PayTransferUnifiedDto reqDto) {
        throw new UnsupportedOperationException("待实现");
    }

    @Override
    protected ClientPayTransferDto doGetTransfer(String outTradeNo) {
        throw new UnsupportedOperationException("待实现");
    }

}
